package com.jwtproject.bootserver.handler;

import com.jwtproject.bootserver.exception.ProjectException;
import com.jwtproject.bootserver.util.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

@Slf4j
@Component
@RestControllerAdvice
public class CustomExceptionHandler {

    /**
     * 自定义业务异常
     */
    @ResponseBody
    @ExceptionHandler(ProjectException.class)
    public Result businessException(HttpServletRequest request, ProjectException e) {
        log.info(e.getMsg());
        return new Result(e.getMsg(),e.getCode(),null);
    }
}
